| Conditions | 5 |
| Paths | 18 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 26 | function httpRequest(file,data,type) { |
||
| 27 | var xhrObject = null; |
||
| 28 | var isChrome = navigator.userAgent.toLowerCase().indexOf("chrome") > -1; |
||
| 29 | |||
| 30 | if (document.getElementById("menu_action") !== null) { |
||
| 31 | document.getElementById("menu_action").value = "action"; |
||
| 32 | } |
||
| 33 | |||
| 34 | if(window.XMLHttpRequest) { // Firefox |
||
| 35 | xhrObject = new XMLHttpRequest(); |
||
| 36 | } else if(window.ActiveXObject) { // Internet Explorer |
||
| 37 | xhrObject = new ActiveXObject("Microsoft.XMLHTTP"); //Info IE8 now supports => xhrObject = new XMLHttpRequest() |
||
| 38 | } else { // XMLHttpRequest non support? par le navigateur |
||
| 39 | alert("Your browser does not support XMLHTTPRequest objects ..."); |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | |||
| 43 | if (type === "GET") { |
||
| 44 | xhrObject.open("GET", file+"?"+data, true); |
||
| 45 | xhrObject.send(null); |
||
| 46 | } else { |
||
| 47 | xhrObject.open("POST", file, true); |
||
| 48 | xhrObject.onreadystatechange = function() { |
||
| 49 | if(xhrObject.readyState === 4) { |
||
| 50 | eval(xhrObject.responseText); |
||
| 51 | //Check if query is for user identification. If yes, then reload page. |
||
| 52 | if (data !== "" && data !== undefined && data.indexOf("ype=identify_user") > 0 ) { |
||
| 53 | if (isChrome === true ) { |
||
| 54 | // Needed pause for Chrome |
||
| 55 | PauseInExecution(100); |
||
| 56 | } |
||
| 57 | if (type === "") { |
||
| 58 | if (document.getElementById("erreur_connexion").style.display === "") { |
||
| 59 | //rise an error in url. This in order to display the eror after refreshing |
||
| 60 | window.location.href = "index.php?error=rised"; |
||
| 61 | } else { |
||
| 62 | window.location.href = "index.php"; |
||
| 63 | } |
||
| 64 | } else { |
||
| 65 | if (type === "?error=rised") { |
||
| 66 | if (document.getElementById("erreur_connexion").style.display === "none") type = ""; //clean error in url |
||
| 67 | else type = "?error=rised"; //Maintain the ERROR |
||
| 68 | } |
||
| 69 | window.location.href = "index.php"+type; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | xhrObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8"); |
||
| 75 | xhrObject.send(data); |
||
| 76 | } |
||
| 77 | } |